// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

const int N = 450, M = N * N * 2;

vector<int> G[M];

int id[N][N][2];

int n, m;
char mp[N][N];

bitset<M> *dp[M];

int deg[M];

inline void add(int u, int v) {
    ++deg[v];
    G[u].push_back(v);
}

void right(int i, int j, int idx) {
    if (j+1>=m)
        return;
    int id2 = idx ^ (mp[i][j] != mp[i][j+1]);
    add(id[i][j+1][id2], id[i][j][idx]);
}

void left(int i, int j, int idx) {
    if (j-1<0)
        return;
    int id2 = idx ^ (mp[i][j] != mp[i][j-1]);
    add(id[i][j-1][id2], id[i][j][idx]);

}

void up(int i, int j, int idx) {
    if (i-1<0)
        return;
    int id2 = idx;
    add(id[i-1][j][id2], id[i][j][idx]);
}

void down(int i, int j, int idx) {
    if (i+1>=n)
        return;
    int id2 = idx;
    add(id[i+1][j][id2], id[i][j][idx]);
}

int ans[N][N], tot;
void topo() {
    static int que[M], st, ed;
    st = ed = 0;
    for (int i=0; i<tot; ++i) {
        if (deg[i] == 0) {
            dp[i] = new bitset<M>;
            dp[i]->reset();
            que[ed++] = i;
        }
    }

    for (int i=0; i<n; ++i)
        memset(ans[i], 0x3f3f3f3f, 4 * (m + 1));

    while (st < ed) {
        int now = que[st++];
        for (int v : G[now]) {
            if (dp[v] == NULL) {
                dp[v] = new bitset<M>;
                dp[v]->reset();
            }
            *dp[v] |= *dp[now];
            (*dp[v])[now] = (*dp[v])[now^1] = 1;
            --deg[v];
            if (deg[v] == 0)
                que[ed++] = v;
        }
        int x = now / 2 / m, y = now / 2 % m;
        ans[x][y] = min(ans[x][y], (int)dp[now]->count() + 1 + 1);
        delete dp[now];
    }
}

int main(int argc, char const *argv[]) {
    // code
    scanf("%d%d", &n, &m);
    // int tot = 0;
    for (int i=0; i<n; ++i) {
        scanf("%s", mp[i]);
        for (int j=0; j<m; ++j) {
            id[i][j][0] = tot++;
            id[i][j][1] = tot++;

        }
    }

    for (int i=0; i<n; ++i)
        for (int j=0; j<m; ++j) {
            if (mp[i][j] == 'N') {
                up(i, j, 0);
                right(i, j, 0);
                down(i, j, 1);
                left(i, j, 1);
            } else {
                up(i, j, 0);
                left(i, j, 0);
                down(i, j, 1);
                right(i, j, 1);
            }
        }

    topo();
    for (int i=0; i<n; ++i)
        for (int j=0; j<m; ++j)
            printf("%d%c", ans[i][j] == 0x3f3f3f3f ? -1 : ans[i][j], j==m-1? '\n':' ');

    return 0;
}
